package dk.twu.analyzer.core;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Tao Wu on 19/04/2015.
 */
public class WindowCreator {
    public static List<Window> createSizedWindow(LocalDate date, MarketDuration duration, ChronoUnit unit, int size) {
        List<Window> windows = new ArrayList<>();
        Iterator<LocalTime> iteTimerUnits = duration.getTimeUnits().iterator();
        while (iteTimerUnits.hasNext()) {
            LocalTime windowStart = iteTimerUnits.next();
            LocalTime windowEnd = windowStart.plus(size, unit);
            if (windowEnd.isBefore(duration.getLastUnit())) {
                windows.add(new Window(date.atTime(windowStart), unit, size));
            }
        }
        return windows;
    }

    public static Window createFullWindow(LocalDate date, MarketDuration duration, ChronoUnit unit) {
        return new Window(date.atTime(duration.getFirstUnit()), unit, duration.getTimeUnits().size());
    }
}
